const path = require('path');
// const poststylus = require('poststylus');
// const pxtorem = require('postcss-pxtorem');

// const webpack = require("webpack");

function resolve(dir) {
  return path.join(__dirname, dir);
}

module.exports = {
  publicPath: './',
  assetsDir: 'static',
  outputDir: process.env.OUTPUT_DIR,
  productionSourceMap: false,
  css: {
    loaderOptions: {
      stylus: {
        // use: [
        //   poststylus([
        //     pxtorem({
        //       rootValue: 100,
        //       propWhiteList: []
        //     }),
        //     'autoprefixer'
        //   ])
        // ],
        import: [
          resolve('src/assets/stylus/theme.custom')
        ]
      }
    }
  },
  chainWebpack: config => {
    if (process.env.NODE_ENV === 'development') {
      config.merge({
        devServer: {
          overlay: {
            warnings: true,
            errors: true
          },
          open: true,
          // 查阅 https://github.com/vuejs/vue-docs-zh-cn/blob/master/vue-cli/cli-service.md#配置代理
          proxy: {
            '/api': {
              target: 'https://10.40.107.155:8443', // 测试环境
              // target: 'https://211.103.0.38:8081', // 现网环境
              changeOrigin: true,
              secure: false,
              pathRewrite: {
                '^/api': ''
              }
            },
            '/gate': {
              target: 'https://10.40.107.155:8082/api-gate/', // 测试环境
              // target: 'https://211.103.0.38:8081/api-gate/', //  现网环境
              changeOrigin: true,
              secure: false,
              pathRewrite: {
                '^/gate': ''
              }
            }
          } // string | Object
        }
      });
    }

    config.externals({
      echarts: 'echarts'
    });

    config.resolve.alias
      .set('@', resolve('src'));
  }
};
